#include "DXShader.h"
#include "DXHelper.h"

#include <D3DX11.h>


DXShader::DXShader(ID3D11Device *pDevice)
	: m_pDevice(pDevice)
{

}


DXShader::~DXShader(VOID)
{
	ReleaseCOM(m_pFX);
}


VOID DXShader::BuildShaderFile(std::string filename)
{
	DWORD       shaderFlags     = 0;
	ID3D10Blob *compiledShader  = 0;
	ID3D10Blob *compilationMsgs = 0;
	HRESULT hr = D3DX11CompileFromFile(filename.c_str(), 0, 0, 0, "fx_5_0", shaderFlags, 0, 0, &compiledShader, &compilationMsgs, 0);
	if(compilationMsgs != 0)
	{
		MessageBoxA(0, (CHAR*)compilationMsgs->GetBufferPointer(), 0, 0);
		ReleaseCOM(compilationMsgs);
	}
	if(FAILED(hr))
	{
		DXTrace(__FILE__, (DWORD)__LINE__, hr, "D3DX11CompileFromFile", TRUE);
	}
	HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, m_pDevice, &m_pFX));
	ReleaseCOM(compiledShader);
}